package spen;

/*******************************************
 By Evan X Merz
 Summer 2008
 A tutorial file from www.thisisnotalabel.com
 *******************************************/

// GUI stuff

import javax.swing.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener; // File input/output

public class wavIOTest extends JFrame implements MouseListener {
    JButton btnGetInfo;
    JTextField txtInputFile;
    JLabel lblOutput;

    // this is what the java app will execute when this program is started
    public static void main(String args[]) {
        new wavIOTest();
    }

    // this is our constructor
    public wavIOTest() {
        setLayout(null); // tell java not to organize our controls automatically

        txtInputFile = new JTextField("dt_2_21_1_003.wav");
        txtInputFile.setBounds(0, 0, 200, 20);
        getContentPane().add(txtInputFile);

        btnGetInfo = new JButton("Get Wav Info");
        btnGetInfo.setBounds(200, 0, 100, 20);
        btnGetInfo.addMouseListener(this);
        getContentPane().add(btnGetInfo);

        lblOutput = new JLabel("");
        lblOutput.setBounds(0, 20, 300, 280);
        getContentPane().add(lblOutput);

        // show the application window
        setTitle("java WAV IO Test");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(300, 300);
        setVisible(true);
    }

// ============
// MOUSE EVENTS

    // ============
    // when the mouse is pressed on one of our controls

    public void mousePressed(MouseEvent e) {
        // when the user clicks the Play button
        if (e.getSource() == btnGetInfo) {
            wavIO wavFile = new wavIO(txtInputFile.getText());
            if (wavFile.read() == true) {
                lblOutput.setText(wavFile.getSummary());

                // now save the file
                wavFile.setPath("testout.wav");
                wavFile.save();
            } else {
                lblOutput.setText("Error!");
            }
        }
    }

    public void mouseReleased(MouseEvent e) {
    }

    public void mouseClicked(MouseEvent e) {
    }

    public void mouseEntered(MouseEvent e) {
    }

    public void mouseExited(MouseEvent e) {
    }

}